#ifndef _UART_H
#define _UART_H

#include <reg51.h>

unsigned char inbuf1[20];

uchar change(int a)
{
	uchar b;
	if (a == 0)
		b = '0';
	if (a == 1)
		b = '1';
	if (a == 2)
		b = '2';
	if (a == 3)
		b = '3';
	if (a == 4)
		b = '4';
	if (a == 5)
		b = '5';
	if (a == 6)
		b = '6';
	if (a == 7)
		b = '7';
	if (a == 8)
		b = '8';
	if (a == 9)
		b = '9';

	return b;
}

void delay10ms(unsigned int x)
{

       unsigned char i,j,k;
				while(x--){
					for(i=5;i>0;i--)

					for(j=4;j>0;j--)

					for(k=248;k>0;k--);
				}

}

void DelayXus(uint x) 
{

  uchar i;

  while(x--)
  {

  	for(i=0;i<200;i++);

  }

}

void UsartInit()
{
 SCON = 0x40;   
 TMOD=0X20;   
 PCON=0X00;   
 TH1=0xfd;    
 TL1=0xfd;
 ES=1;      
 EA=1; 
 TI=0;
 RI=0;	
 TR1=1;     
}
void putc_to_SerialPort(uchar c)
{
 	SBUF = c;
	while(TI == 0);
	TI = 0;
}

void puts_to_SerialPort(uchar *s)
{
 	while(*s != '\0')
	{
	 	putc_to_SerialPort(*s++);
		//s++;
		delay10ms(5);
	}
}

//void  serial () interrupt  4  using  3  
//{
//	int i;
//	unsigned char ch;
//     if (RI)
//    {
//        RI =  0 ;
//        ch=SBUF;
//				
//				for(i=0;i<20;i++)
//				{
//				inbuf1[i]=ch;
//				}      
//    }
//}


#endif